/* Copyright (c) 2004-2023 Peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service.processor.user.check;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.manage.core.service.order.UserCreateOrder;
import info.peigen.hotpot.manage.core.service.processor.AbstractHotpotManageServiceProcessor;
import org.noear.solon.annotation.Component;

/**
 * <b>(UserCreatePasswordCheckProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/8/30
 */
@Component
public class UserCreatePasswordCheckProcessor extends AbstractHotpotManageServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 21;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        UserCreateOrder order = (UserCreateOrder) serviceContext.getOrder();
        // 登陆密码与确认登录密码保持一致
        if (StrUtil.isAllNotEmpty(order.getPassword(), order.getConfirmPassword())) {
            Assert.isTrue(StrUtil.equals(order.getPassword(), order.getConfirmPassword()), () -> new BusinessException(ResultCode.PW_AND_CONFIRMPW_IS_NOT_EQUALS));
        }
    }

}
